package projetolp2.GraphicInterface;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Filtro extends MealPoints implements ActionListener{
	
	private JPanel panelMenu = new JPanel(new BorderLayout());
	private JPanel panel0= new JPanel(new GridLayout(0, 1));
	private JPanel panel1= new JPanel(new GridLayout(0, 1));
	private JPanel panel2= new JPanel(new GridLayout(0, 1));
	private JPanel panel3= new JPanel(new GridLayout(0, 1));
	private JPanel panel4= new JPanel(new GridLayout(0, 1));
	private JPanel panel5= new JPanel(new GridLayout(0, 1));

	private JButton VOLTAR = new JButton(NomeBotoes.values()[idioma(IDIOMAPROGRAMA )].getVoltar());
	private JButton BUSCAR = new JButton(NomeBotoes.values()[idioma(IDIOMAPROGRAMA )].getContinuar());
	private JComboBox FILTRO1 = new JComboBox();
	private JComboBox FILTRO2 = new JComboBox();
	private JComboBox FILTRO3 = new JComboBox();

	final JLabel label = new JLabel("Escolha o tipo de sugestao: ");
	
	private JPanel panelFinal = new JPanel();
	private JPanel panelFinal2 = new JPanel();
	private JPanel panelFinal3 = new JPanel(new GridLayout(0, 1));
	public Filtro(){
		FILTRO1.addItem("Tipo");
		FILTRO1.addItem("Cantina");
		FILTRO1.addItem("Boteco");
		FILTRO1.addItem("Restaurante");
		
		FILTRO2.addItem("Almoço");
		FILTRO2.addItem("Prato-feito");
		FILTRO2.addItem("A la carte");
		FILTRO2.addItem("Self-servide");
		
		FILTRO3.addItem("Local");
		FILTRO3.addItem("Centro");
		FILTRO3.addItem("Shopping");
		FILTRO3.addItem("UFCG");
		
	}
	private void ajudaDeBotoes(){
		VOLTAR.setToolTipText("Voltar a janela anterior");		
		BUSCAR.setToolTipText("Buscar os estabelecimentos contrários as seleções");		
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource() == VOLTAR){
			removerAdicionar(sugestoespersonalizadasFiltro,sugestoespersonalizadas);	
		}
		else if(e.getSource() == BUSCAR){
			if(!FILTRO1.getSelectedItem().toString().equals("Tipo")){
				if(FILTRO1.getSelectedItem().toString().equals("Boteco")){
					((Filtropag2) sugestoesFiltropg2).tipo("bar");	
				}else{
				((Filtropag2) sugestoesFiltropg2).tipo(FILTRO1.getSelectedItem().toString());
				}
			}else{
				((Filtropag2) sugestoesFiltropg2).tipo(null);
			}
			if(!FILTRO2.getSelectedItem().toString().equals("Almoço")){
				((Filtropag2) sugestoesFiltropg2).almoco((String) FILTRO2.getSelectedItem().toString());
			}else{
				((Filtropag2) sugestoesFiltropg2).almoco(null);
			}
			if(!FILTRO3.getSelectedItem().toString().equals("Local")){
				((Filtropag2) sugestoesFiltropg2).local((String) FILTRO3.getSelectedItem().toString());
			}else{
				((Filtropag2) sugestoesFiltropg2).local(null);
			}
			//quantidadeSugestoes.abilitaDesabilita(true, "FILTRO");
			removerAdicionar(sugestoespersonalizadasFiltro,((Filtropag2) sugestoesFiltropg2).panel());	
		}
	}
	private void createComponents() {
		ajudaDeBotoes();
		
		VOLTAR.setMnemonic(KeyEvent.VK_I);
        VOLTAR.addActionListener(this);
        label.setLabelFor(VOLTAR);
        
        BUSCAR.setMnemonic(KeyEvent.VK_I);
        BUSCAR.addActionListener(this);
        label.setLabelFor(BUSCAR);
        
        panel0.add(BUSCAR);
        panel0.setBorder(BorderFactory.createEmptyBorder(
                5, //top
                10, //left
                5, //bottom
                10) //right
                );
        panel1.add(VOLTAR);
        panel1.setBorder(BorderFactory.createEmptyBorder(
                5, //top
                10, //left
                5, //bottom
                10) //right
                );
        panel2.add(FILTRO1);
        panel2.setBorder(BorderFactory.createEmptyBorder(
                5, //top
                10, //left
                5, //bottom
                10) //right
                );
        panel3.add(FILTRO2);
        panel3.setBorder(BorderFactory.createEmptyBorder(
                5, //top
                10, //left
                5, //bottom
                10) //right
                );
        panel4.add(FILTRO3);
        panel4.setBorder(BorderFactory.createEmptyBorder(
                5, //top
                10, //left
                5, //bottom
                10) //right
                );
        panel5.add(label);
        panel5.setBorder(BorderFactory.createEmptyBorder(
                5, //top
                10, //left
                5, //bottom
                10) //right
                );
        panelFinal.add(panel2);
        panelFinal.add(panel3);
        panelFinal.add(panel4);
        panelFinal.add(panel0);
        panelFinal.add(panel1);
        panelFinal2.add(panel5);
        //panelMenu.add(panelFinal,BorderLayout.NORTH);
        panelFinal3.add(panelFinal2);
        panelFinal3.add(panelFinal);
        panelMenu.add(panelFinal3,BorderLayout.NORTH);
		
    }
	public Component panel(){
		createComponents();
		panelMenu.setBackground(Color.white);
		panelMenu.setVisible(true);
		
		
		return panelMenu;
	}	
}